//
//  QSVerifyTool.m
//  ZengLongSeSha
//
//  Created by apple on 2017/6/22.
//  Copyright © 2017年 Song. All rights reserved.
//

#import "QSVerifyTool.h"
#import "QSSingleton.h"

@implementation QSVerifyTool

/**
 *  验证手机号
 */
+ (BOOL)checkMobilePhoneNumber:(NSString *)number
{
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:number];
}

/**
 *  验证手机号以及固话
 */
+ (BOOL)checkPhoneNumber:(NSString *)number
{
    NSString *phoneNum = [number stringByReplacingOccurrencesOfString:@"-" withString:@""];
    
    //验证输入的固话中不带 "-"符号
    NSString * strNum = @"^(0[0-9]{2,3})?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\\d{8}$)";
    
    //验证输入的固话中带 "-"符号
    //    NSString * strNum = @"^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$|(^(13[0-9]|14[5|7|9]|15[0-9]|17[0|1|3|5|6|7|8]|18[0-9])\\d{8}$)";
    
    NSPredicate *checktest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", strNum];
    
    return [checktest evaluateWithObject:phoneNum];
}

/**
 *  邮箱验证
 */
+ (BOOL)checkEmailStr:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

/**
 *  身份证号验证
 */
+ (BOOL)checkIDCardNumber:(NSString *)idCardNumber
{
    NSString *idCardNumberStr = @"^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$";
    NSPredicate *idCardNumberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",idCardNumberStr];
    return [idCardNumberPre evaluateWithObject:idCardNumber];
}

/**
 *  对6-20位必须包含字母数字的密码进行匹配
 */
+ (BOOL)checkPassword:(NSString *)password
{
    NSString *passwordStr = @"^(?!^\\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{6,20}$";
    NSPredicate *passwordPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passwordStr];
    return [passwordPre evaluateWithObject:password];
}
@end
